<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use common\helpers\StringHelper;
use yii\bootstrap\Modal;
use johnitvn\ajaxcrud\CrudAsset;

$this->title = '';
CrudAsset::register($this);
?>
<div class="blog-index">

    <p>Name: <span style="font-weight: bold;"><?= Html::encode($team->name) ?></span></p>

    <?= GridView::widget([
        'responsiveWrap' => false,
        'dataProvider' => $dataProvider,
        'columns' => [
            'id',
            'userid',
            'username',
            [
                'attribute' => 'ismanager',
                'label' => 'Ismanager',
                'format'=>'raw',
                'value' => function ($model){
                    return $model->ismanager ? "<span style='color: red;'>manager</span>" : "";
                }
            ],
            [
                'attribute' => 'ctime',
                'label' => 'Ctime',
                'format'=>'raw',
                'value' => function ($model){
                    return date("Y-m-d H:i:s",$model->ctime);
                }
            ],
            [
                'class' => 'kartik\grid\ActionColumn',
                'template' => '{delete-teamuser}',
                'buttons' => [
                    'delete-teamuser' => function ($url, $model) {
                        return html::button("delete",['title' => Yii::t('yii', 'delete'),'class' => 'btn btn-default delete','data-id'=>$model->id]);
                    }
                ]
            ],
        ],
    ]); ?>
</div>
<?php Modal::begin([
    "id" => "ajaxCrudModal",
    "options" => ["tabindex" => ""],
    "footer" => "",
]) ?>
<?php Modal::end(); ?>

<script type="text/javascript">
    $(".delete").click(function () {
        if(confirm("delete this item ？")){
            $(this).attr('disabled','desabled');
            var id = $(this).data('id');

            $.ajax({
                type:"get",
                url:"/user/delete-teamuser?id="+id,
                success:function (ret) {
                    if( ret ){
                        $("#w0-container table tr[data-key='"+id+"']").hide();
                    }
                }
            });
        }
    });
</script>
